unit UnitCalculoComissao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UnitModelo, Grids, DBGrids, SMDBGrid, DB, ImgList, ActnList,
  ADODB, ComCtrls, ToolWin, StdCtrls, Mask, ExtCtrls, DBCtrls, jpeg;

type
  TFormCalculoComissao = class(TFormModelo)
    qryDadosCALGUIA_DESCRICAO: TStringField;
    qryDadosCALGUIA_CODIGO: TAutoIncField;
    SMDBGrid1: TSMDBGrid;
    qryItens: TADOQuery;
    dsItens: TDataSource;
    qryItensCALGUIA_CODIGO: TIntegerField;
    qryItensCALITEM_LIMINFERIOR: TIntegerField;
    qryItensCALITEM_LIMSUPERIOR: TIntegerField;
    qryItensCALITEM_VALOR: TBCDField;
    Panel2: TPanel;
    DBText1: TDBText;
    Label1: TLabel;
    procedure actNovoExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure qryItensAfterInsert(DataSet: TDataSet);
    procedure actAlterarExecute(Sender: TObject);
    procedure qryDadosAfterOpen(DataSet: TDataSet);
    procedure qryDadosBeforeClose(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCalculoComissao: TFormCalculoComissao;

implementation

uses UnitPrincipal, UnitCadCalculoComissao;

{$R *.dfm}

procedure TFormCalculoComissao.actNovoExecute(Sender: TObject);
begin
  inherited;
  FormPrincipal.cnRegente.BeginTrans;
  qryDados.Insert;
  if FormCadCalculoComissao = nil then
    FormCadCalculoComissao := TFormCadCalculoComissao.Create(Self);
  if FormCadCalculoComissao.ShowModal = mrOk then
    FormPrincipal.cnRegente.CommitTrans
  else
  begin
    FormPrincipal.cnRegente.RollbackTrans;
    qryDados.Refresh;
  end;
end;

procedure TFormCalculoComissao.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  FormCalculoComissao := nil;
end;

procedure TFormCalculoComissao.qryItensAfterInsert(DataSet: TDataSet);
begin
  inherited;
  if qryDados.State = dsInsert then
    qryDados.Post;
  qryItensCALGUIA_CODIGO.Value := qryDadosCALGUIA_CODIGO.Value;
end;

procedure TFormCalculoComissao.actAlterarExecute(Sender: TObject);
begin
  inherited;
  FormPrincipal.cnRegente.BeginTrans;
  qryDados.Edit;
  if FormCadCalculoComissao = nil then
    FormCadCalculoComissao := TFormCadCalculoComissao.Create(Self);
  if FormCadCalculoComissao.ShowModal = mrOk then
    FormPrincipal.cnRegente.CommitTrans
  else
  begin
    FormPrincipal.cnRegente.RollbackTrans;
    qryDados.Refresh;
  end;
end;

procedure TFormCalculoComissao.qryDadosAfterOpen(DataSet: TDataSet);
begin
  inherited;
  qryItens.Open;
end;

procedure TFormCalculoComissao.qryDadosBeforeClose(DataSet: TDataSet);
begin
  inherited;
  qryItens.Close;
end;

end.
